//index.js
//获取应用实例
var util = require('../../utils/util.js')
var config = require('../../config.js')
var app = getApp()
var serverUrl=util.getImgUrl();
// var serverUrl = 'http://skyforest.static.elab-plus.com/wepy_pro/'
Page({
  onShareAppMessage: function () {
	  if(app.globalData.single.loginid){
	  return {
      title: '宁波WIII',
      imageUrl: serverUrl+'wepy_pro/index.png',
      path: '/pages/index/index?loginid='+app.globalData.single.loginid
    }	  
	  }else{
		  return false
	  }
  
  },
  data: {
    InitFlag:"0",
    homeLocation:{},  // 地段分析
    home3D:{},        // 3D看房
    homeMoment:{},    // 此时此刻
    homeBanner:{},    // 顶部BANNER
    homeCollect:{},   // 精彩图集
    homeInvest:{},    // 投资必看
    homeLive:{},      // 自住必看
    homeFeature:{},   // 项目特色（最新动态）
    homePapa:{},      // 爬爬（宁波行情牌价）
    Height:"1070",
    showPhoneModel:false,
    showInfoModel:false,
    isSend: false,
    showPhoneAuth:false,
    showAgree:false,
    indexLiudian:false,
    showAuth:true,
    // phoneGoUrl:"",
    phoneFun:null,
    phoneFailFun:null,
    infoFun:null,
    infoFailFun:null,
    appid: "",
    flag: false,
    name:"",
    // imgUrl:config.imageUrl,
    motto: 'Hello World',
    currentTab:"0",
    userInfo: {},
    verifyText: '获取验证码',
    verifyCode: '',
    tel:'',
  },
  // 跳转项目价值
  goToProjectValue:function(){
      wx.navigateTo({
          url:'../projectValue/projectValue'
      })
      // this.authorizeInfo(function(){
      //   wx.navigateTo({
      //     url:'../projectValue/projectValue'
      //   })
      // });
  },

  // 跳转投资保障
  goToSecurity:function(){
      wx.navigateTo({
          url:'../security/security'
      })
      // this.authorizeInfo(function(){
      //   wx.navigateTo({
      //     url:'../security/security'
      //   })
      // });
  },
  // 跳转一人居
    goToHabitat:function(){
      // this.authorizeInfo(function(){
      //   wx.navigateTo({
      //     url:'../habitat/habitat'
      //   })
      // });
      wx.navigateTo({
          url:'../habitat/habitat'
        })
  },
  // 我要分享
  goToShare:function(){
    wx.navigateTo({
        url:'../share/share'
      })
    // this.authorizePhone(function(){
    //   wx.navigateTo({
    //     url:'../share/share'
    //   })
    // });
  },
  /*** 滑动切换tab***/
  bindChange: function (e) {
    var that = this;
    // console.log(e)
    if(e.detail.source=="autoplay"){
      return false;
    }
    var myheight="";
    if(e.detail.current == "1"){
      myheight="600"
    }
    else{
      myheight=this.data.homePapa.isShow=='0'? "700" : "1070";
      console.log("this.data.homePapa.isShow,",this.data.homePapa.isShow,myheight)
    }
    that.setData({
      Height:myheight,
      currentTab: e.detail.current
    });
  },
  /*** 点击tab切换***/
  swichNav: function (e) {
    console.log('滑动切换',e)
    var that = this;
    var myheight="";
    if(e.target.dataset.current == "1"){
      myheight="600"
    }
    else{
      myheight=this.data.homePapa.isShow=='0'? "700" : "1070"
      console.log("this.data.homePapa.isShow,",this.data.homePapa.isShow,myheight)
    }
    that.setData({
      Height:myheight,
      currentTab: e.target.dataset.current
    });
  },
  //图片点击事件
  imgYu:function(event){
    var src = event.currentTarget.dataset.src;//获取data-src
    // var imgList = event.currentTarget.dataset.list;//获取data-list
    var list =[];
    this.data.homeCollect.forEach(function(item,index){
      list.push(item.jumpUrl);
    });
    console.log("***src***",src)
    this.setLike(event.currentTarget.dataset.like);
    // wx.navigateTo({
    //   url: '../scaleImg/scaleImage?img='+ src
    // })
    // console.log(src,list)
    // //图片预览
    wx.previewImage({
      current:src, // 当前显示图片的http链接
      urls: list, // 需要预览的图片http链接列表
      success:function(e){
        console.log(e)
      }
	})
	
	var obj={
        "pageid":'10941001',
        "keyvalue":'sfc.nb.xcx.w3.head.jctj.click',
    }
    util.reqTrackEventObj(obj,app);
	
  },
  setLike: function (url) {
    // console.log(e.detail.errMsg)
    var self = this;
    var data={
      houseId: app.globalData.houseid,
      picUrl:  url,
      numberType: '1', // 数字类型(1点赞数|2观看数|3点击数)
      uniqueId: app.globalData.openid,
    }
    wx.request({
      url: util.url(),
      method: 'POST',
      data: util.reformParam(util.likeUrl, data),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success:function(res){
        if(res.data.success && res.data.single){
          console.log("***like***",res.data.single)
          // app.globalData.like={"url":self.data.dataimg}
          // wx.showToast({
          //   title: '点赞成功',
          //   icon: 'success',
          //   duration: 1000
          // })
            var homeCollect =self.data.homeCollect;
            homeCollect.forEach(function(item,index){
              if(item.linkUrl == url){
                item.likeCount= (Number(item.likeCount)+1).toString();
              }
            });
            self.setData({
              homeCollect: homeCollect,
            });
        }
        else{
          console.log("***Scale-setLike***",res);
        }
      }
    })
  },
  // 展示web-view
  goWebView: function (e) {
    // console.log(e);
    var self =this;
    var url=e.currentTarget.dataset.url;
    if(url.includes("/layout")){

        wx.showToast({
            title: '敬请期待...',
            icon: 'warn',
            duration: 1500,
        })
        return false;
    }
    var linkUrl=e.currentTarget.dataset.srcurl;
    var imgUrl=e.currentTarget.dataset.img;//分享图片
    var parm="";
    var view=encodeURIComponent(url);
    if(url==null || url.indexOf('http')!=0){
      return false;
    }
    console.log("***linkUrl***",linkUrl)
    if(linkUrl){
      var data={
        houseId: app.globalData.houseid,
        picUrl:  linkUrl,
        numberType: '2', // 数字类型(1点赞数|2观看数|3点击数)
        status:"1", // 1观看，-1 不观看
        uniqueId: app.globalData.openid,
      }
      wx.request({
        url: util.url(),
        method: 'POST',
        data: util.reformParam(util.likeUrl, data),
        header: {
          'content-type': 'application/json' // 默认值
        },
        success:function(res){
          console.log()
          if(res.data.success && res.data.single){
            console.log("***like***",res.data.single)
              var home3D =self.data.home3D;
              home3D.viewCount= Number(home3D.viewCount)+1;
              self.setData({
                home3D: home3D,
              });
          }
          else{
            console.log("***Scale-setLike***",res);
          }
        }
      })
    }
    
    var pageid=e.currentTarget.dataset.pageid;
    var key=e.currentTarget.dataset.key;
    
    // console.log("goWebView",url,view,app.globalData.single.loginid)
    // this.authorizeInfo(function(){
      var obj={
        "pageid":pageid,
        "keyvalue":key + ".enter",
      }
      util.reqTrackEventObj(obj,app);
      var obj={
        "pageid":pageid,
        "keyvalue":key + ".statetime",
        "usetime":"3000", // 使用时长
      }
      util.reqTrackEventTimeObj(obj,app);
      wx.navigateTo({
        url: '../webView/webView?view='+view+"&linkUrl="+linkUrl+"&imgUrl="+imgUrl
      })
    // });
  },
  // 播放视频
  goVideo: function (e) {
    // console.log(e);
    var self = this;
    // var url=e.currentTarget.dataset.source;
    var linkUrl=e.currentTarget.dataset.srcurl;
    var parm="";
    
    console.log("linkUrl",linkUrl)
    // this.authorizeInfo(function(){
      // self.reqVideoInfo(linkUrl);
    // });
    var data={
      houseId: app.globalData.houseid,
      picUrl:  linkUrl,
      numberType: '2', // 数字类型(1点赞数|2观看数|3点击数)
      status:"1", // 1观看，-1 不观看
      uniqueId: app.globalData.openid,
    }
    wx.request({
      url: util.url(),
      method: 'POST',
      data: util.reformParam(util.likeUrl, data),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success:function(res){
        if(res.data.success && res.data.single){
            console.log("***like-homeMoment.viewCount***",res.data.single);
            self.reqVideoInfo(linkUrl,res.data.single.id);
            var homeMoment =self.data.homeMoment;
            homeMoment.viewCount= Number(homeMoment.viewCount)+1;
            self.setData({
              homeMoment: homeMoment,
            });
        }
        else{
          console.log("***Scale-setLike***",res);
        }
      }
    })
  },
  reqVideoInfo:function(linkUrl,id){
    var self = this;
    var data={
      houseid: app.globalData.houseid,
    }
    wx.request({
      url: util.url(),
      method: 'POST',
      data: util.reformParam(util.videoInfo, data),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success:function(res){
        if(res.data.success && res.data.list){
          console.log("***like***",res.data.list)
          // 用户已经授权
          wx.navigateTo({
            url: '../video/video?source='+encodeURI(decodeURI(res.data.list[0].video_url))+"&linkUrl="+linkUrl+"&id="+id
          })
        }
        else{
          console.log("***reqVideoInfo***",res);
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 1000
          })
        }
      }
    })
  },
  userCheck:function(e){
    console.log(e.target.dataset.name);
    wx.navigateTo({
      url: '../detail/detail?id='+ e.target.dataset.name
    })

  },
  come:function(e){
    var id = this.data.userInfo.nickName
    wx.navigateTo({  
        url: '../chatList/chatList'
    })
  },
  log: function (e) {
    var id = this.data.userInfo.nickName
    wx.navigateTo({
      // url: '../logs/logs'
      url: '../multiroom/roomlist/roomlist'
    })
  },
  // 同意授权
  agree:function(e){
    var obj={
        "pageid":'10941001',
        "keyvalue":'sfc.nb.xcx.w3.head.shifouliudian.click',
    }
    util.reqTrackEventObj(obj,app);
    // showAgree:false, 显示同意的文字
    // showAuth:true,
    this.setData({
        showAgree: true
    })
  },
  // 不同意授权
  noagree:function(e){
    this.setData({
        showAuth: false
    })
  },
  //顾问列表
  counselorList:function(e){
    var id = this.data.userInfo.nickName
    wx.navigateTo({
        url: '../counselorList/counselorList'
    })
  },
  //投资自住
  investment:function(){
	   wx.navigateTo({
        url: '../investment/investment'
    })
    //  this.authorizeInfo(function(){
    //   wx.navigateTo({
    //     url: '../investment/investment'
    //   })
    // });
  },
  //自住一人
  occupied:function(){
	   wx.navigateTo({
        url: '../occupied/occupied'
    })
    // this.authorizeInfo(function(){
    //   wx.navigateTo({
    //     url: '../occupied/occupied'
    //   })
    // });
  },
  //消息通知
  goToNoticeList:function(){
    console.log("***goToNoticeList-authorizePhone***",app.globalData.phone)
    // this.authorizePhone(function(){
    //   wx.navigateTo({
    //     url: '../noticeList/noticeList'
    //   })
    // });
    wx.navigateTo({
        url: '../noticeList/noticeList'
      })
  },
  //我分享的好友
  goToShareFriend:function(){
    console.log("***goToShareFriend-authorizePhone***",app.globalData.phone)
    // this.authorizePhone(function(){
    //   wx.navigateTo({
    //     url: '../shareFriend/shareFriend'
    //   })
    // });
    wx.navigateTo({
        url: '../shareFriend/shareFriend'
      })
  },
  video: function (e) {
    var id = this.data.userInfo.nickName;
    wx.navigateTo({
      // url: '../logs/logs'
      url: '../multiroom/chatlist/chatList'
    })
  },
  goChatList:function(e){
      app.globalData.userInfo = e.detail.userInfo;
      var isSend = wx.getStorageSync('isSend');
      if (!isSend) {//没聊天
          wx.navigateTo({
              url: '../counselorList/counselorList'
          })
      } else {
          wx.navigateTo({
              url: '../messagesList/messagesList'
          })
      }

  },
  
  goxzs:function(e){
    console.log(e.detail.rawData)
    app.globalData.userInfo=e.detail.userInfo
    wx.setStorageSync('userInfo', e.detail.userInfo);
    // var id = this.data.userInfo.nickName
    wx.navigateTo({
        // url: '../logs/logs'
        url: '../multiroom/aide/aide'
      })
  },
  onLoad: function (options) {
    var that = this
    // console.log(options,'yyyy')
    console.log("***onLoad***",options,options.loginid);
    //将渠道存至全局，留电接口需要用
    app.globalData.fromChannel = options.loginid||'小程序';
    that.getInitData();
    // 获得用户授权
    // that.authorizePhone();
    // that.authorizeIndexInfo(function(){
    //   that.authorizeIndexPhone();
    // },function(){
    //   that.authorizeIndexPhone();
    // });
    that.authorizeIndexPhone();
  },
  onReady:function(){
    // console.log("-----++++-dfghkdsfhjsdklfjhk",this.data.homePapa)
    // if(this.data.homePapa.isShow == "0"){
    //   this.data.papaHeight="600";
    //   console.log("------dfghkdsfhjsdklfjhk",this.data.homePapa.isShow)
    // }
  },
  proto_getLoginInfo: function () {
    wx.request({
      url: util.url(),
      method: 'POST',
      data: util.reformParam(util.tencentSignature, { identifier: app.globalData.identifier, appId: '1400091043' }),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (ret) {
        if (ret.data.code) {
          console.log('获取登录信息失败，调试期间请点击右上角三个点按钮，选择打开调试');
          wx.showToast({
            title: ret.data.message + '[' + ret.data.code + ']',
            icon: 'warn',
            duration: 1500,
          })
          return;
        }
        console.log('获取usersig登录信息成功',app.globalData.userInfo);
        app.globalData.userSig = ret.data.single.signature;
      },
      fail: function (ret) {
          console.log('获取IM信息失败: ', ret);
          if (ret.errMsg == 'request:fail timeout') {
            wx.showToast({
              title: "网络请求超时，请检查网络状态",
              icon: 'warn',
              duration: 1500,
            })
          }
          else{
            wx.showToast({
              title: ret.errMsg,
              icon: 'warn',
              duration: 1500,
            })
          }
      }
    });
  },
  onShow: function(e){
    var that = this
    console.log("***onShow***",this.data.name);
    wx.showShareMenu({
      withShareTicket: true
    })
    // wx.hideShareMenu() //隐藏转发按钮
    wx.setNavigationBarTitle({
      title: '宁波WIII'
    })
      if(wx.getStorageSync('phone')){
          this.setData({
              showPhoneAuth:true
          })
      }else{
          this.setData({
              showPhoneAuth:false
          })
      }
      if(wx.getStorageSync('indexLiudian')){
          this.setData({
              indexLiudian:true
          })
	  }
    if(!app.globalData.single){
      app.login(function(obj){
          var param={
            "nickname":app.globalData.userInfo?app.globalData.userInfo.nickName:"",
            "mobile":"",
            "source":"3", // 小程序
            "customerHead":app.globalData.userInfo?app.globalData.userInfo.avatarUrl:"",
            "module":app.globalData.fromChannel||"小程序",
            "houseid":app.globalData.houseid,
            "appVersion":"1.0",
            // "openId":app.globalData.openid||"",
            "code":obj.code||"",
            "appId":obj.appid||"",
            "secret":obj.secret||"",
          }
          console.log(param,'param')
          wx.request({
            url: util.url(),
            method: 'POST',
            data: util.reformParam(util.mineLogin, param),
            header: {
              'content-type': 'application/json' // 默认值
            },
            success:function(res){
              console.log("***app.login***",res);
              if(res.data.success){
                if(res.data.single){ // 获取信息成功
                  var data = res.data.single;
                  app.globalData.qrpictureurl = data.qrpictureurl;
                  app.globalData.tonken = data.tonken;
                  app.globalData.single = data;
                  app.globalData.loginid = data.loginid;
                  app.globalData.sessionKey=data.sessionKey;
                  app.globalData.openid = data.openId||"";
                  app.globalData.phone = wx.getStorageSync('phone');
                  app.globalData.identifier = data.id+"_"+data.loginid+"_"+data.houseid;
                  that.proto_getLoginInfo();
                  var obj={
                    "pageid":"10941001",
                    "keyvalue":"sfc.nb.xcx.w3.head.head.enter",
                    // "usetime":"", // 使用时长
                  }
                  util.reqTrackEventObj(obj,app);
                  var obj={
                    "pageid":"10941001",
                    "keyvalue":"sfc.nb.xcx.w3.head.head.statetime",
                    "usetime":"3000", // 使用时长
                  }
                  util.reqTrackEventTimeObj(obj,app);
                }
                else{
                  wx.showToast({
                    title: "数据不存在,请稍后再试",
                    icon: 'warn',
                    duration: 1500,
                  })
                }
              }
              else{
                wx.showToast({
                  title: res.data.message,
                  icon: 'warn',
                  duration: 1500,
                })
              }
            },
            fail: function (ret) {
              console.log('获取信息失败: ', ret);
              if (ret.errMsg == 'request:fail timeout') {
                wx.showToast({
                  title: "网络请求超时，请检查网络状态",
                  icon: 'warn',
                  duration: 1500,
                })
              }
              else{
                wx.showToast({
                  title: ret.errMsg,
                  icon: 'warn',
                  duration: 1500,
                })
              }
            }
        });
      });
    }
    else{
  	  var obj={
    		"pageid":"10941001",
    		"keyvalue":"sfc.nb.xcx.w3.head.head.enter",
    		// "usetime":"", // 使用时长
    	}
    	util.reqTrackEventObj(obj,app);
    	var obj={
    		"pageid":"10941001",
    		"keyvalue":"sfc.nb.xcx.w3.head.head.statetime",
    		"usetime":"3000", // 使用时长
    	}
  	  util.reqTrackEventTimeObj(obj,app);
    }
  },
  getInitData: function () {
    // console.log(e.detail.errMsg)
    var self = this;
    wx.request({
      url: util.url(),
      method: 'POST',
      data: util.reformParam(util.InitUrl, { houseId: app.globalData.houseid }),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success:function(res){
        self.setData({
          InitFlag:"1",
        });
        if(res.data.success){
          if(res.data.single){
            var myheight = res.data.single.homePapa.isShow=='0'? "700" : "1070"
            self.setData({
              homeLocation: res.data.single.homeLocation,
              home3D: res.data.single.home3D,
              homeMoment: res.data.single.homeMoment,
              homeBanner: res.data.single.homeBanner,
              homeCollect: res.data.single.homeCollect,
              homeInvest: res.data.single.homeInvest,
              homeLive: res.data.single.homeLive,
              homeFeature: res.data.single.homeFeature,
              homePapa: res.data.single.homePapa,
              Height: myheight
            });

          }
          else{
            wx.showToast({
              title: "Sorry,数据不存在,请稍后再试",
              icon: 'warn',
              duration: 1500,
            })
          }
        }
        else{
          console.log("***Index-Error-getInitData***",res);
          wx.showToast({
            title: res.data.message + '[' + res.data.errorCode + ']',
            icon: 'warn',
            duration: 1500,
          })
        }
      }
    })
  },
  // 用户授权
  getUserInfo: function (e) {
    var self =this;
    wx.setStorageSync('ISauthorizeInfo',true);// 是否授权过用户基本信息,
    console.log(e.detail,'kkkkkkkkkkkkkkkkkkkk');
    this.setData({
        showInfoModel: false
    })
    if (e.detail.errMsg.includes("fail")){
      wx.showModal({  
          title: '提示',  
          showCancel: false,  
          content: '您点击了拒绝授权,部分功能将无法向您开放',  
          success: function (res) { typeof self.data.infoFailFun == "function" && self.data.infoFailFun();}  
      })

    }
    else{
      app.globalData.userInfo=e.detail.userInfo
      var id = this.data.userInfo.nickName
      wx.setStorageSync('userInfo', e.detail.userInfo);
      typeof self.data.infoFun == "function" && self.data.infoFun(); // 执行回调函数
    }
  },
  // 手机号授权
  getPhoneNumber: function (e) {
    var self = this;
    // 隐藏 
    this.setData({
        showPhoneModel: false
    })
    wx.setStorageSync('ISauthorizePhone',true);// 是否授权过手机号,
    var iv = encodeURIComponent(encodeURIComponent(e.detail.iv));
    var errMsg = e.detail.errMsg;
    var houseid=app.globalData.houseid;
    var token=app.globalData.tonken||"";
    var encryData = encodeURIComponent(encodeURIComponent(e.detail.encryptedData));
    var session = encodeURIComponent(encodeURIComponent(app.globalData.sessionKey));
    var appid = encodeURIComponent(encodeURIComponent(app.globalData.appid));//"wxa6aef323462b8b14";
    
    console.log("***token***",token)
    // var pc = new WXBizDataCrypt(appid, session);
    console.log("****getPhoneNumber****")
    // 用户未授权
    if (e.detail.errMsg.includes("fail")){
        typeof self.data.phoneFailFun == "function" && self.data.phoneFailFun();
    }
    else{
      if(!encryData || !session || !iv){
        wx.showToast({
            title: '系统提示:授权信息错误',
            icon: 'warn',
            duration: 1500,
        })
      }
     var parm={
        encryptedData:encryData,
        sessionKey:session,
        appId:appid,
        houseid:houseid,
        iv:iv
      };
      wx.request({
        url: util.url(),
        method: 'POST',
        data: util.reformParam(util.getPhoneNumber, parm),
        header: {
          'content-type': 'application/json', // 默认值
          'auth_token':token
        },
        success:function(res){
          console.log('解密后 data: ', res);
          if(res.data.success && res.data.single){
            console.log(res.data.single)
            app.globalData.phone = res.data.single;
            wx.setStorageSync('phone', res.data.single);
            self.setData({
              showPhoneModel: false,
              showPhoneAuth:true,
            })
            // 存在跳转的
            typeof self.data.phoneFun == "function" && self.data.phoneFun(); // 执行回调函数
          }
    		},
    		fail:function(res){
          typeof self.data.phoneFailFun == "function" && self.data.phoneFailFun();
    			console.log(res,'解密手机号失败ggggggggggg')
    		}
      });
    }
  },
  authorizePhone(cb,failcb){
    var that = this;
      // app.globalData.phone = wx.getStorageSync('phone');
      console.log("***authorizePhone***",app.globalData.phone,wx.getStorageSync('phone'))
      // 没有获得用户手机号
      if(!wx.getStorageSync('ISauthorizePhone')){
        that.setData({
          showPhoneModel: true,
          phoneFun:cb,
          phoneFailFun:failcb||null
        })
      }
      else{
        that.setData({
          showPhoneModel: false,
          showPhoneAuth:true
        })
        typeof cb == "function" && cb()
      }
  },
  authorizeIndexPhone(cb,failcb){
    var that = this;
    // wx.getStorageSync('ISauthorizePhone');// 是否授权过手机号,
    if(!wx.getStorageSync('ISauthorizePhone')){
      app.globalData.phone = wx.getStorageSync('phone');
      console.log("***authorizeIndexPhone***",app.globalData.phone,wx.getStorageSync('phone'))
      // 没有获得用户手机号
      if(!wx.getStorageSync('ISauthorizePhone')){
        that.setData({
          showPhoneModel: true,
          phoneFun:cb||null,
          phoneFailFun:failcb||null
        })
      }
      else{
        that.setData({
          showPhoneModel: false,
          showPhoneAuth:true
        })
        typeof cb == "function" && cb()
      }
    }
  },
  authorizeInfo(cb,failcb){
    var that = this;
    app.globalData.userInfo = wx.getStorageSync('userInfo');
    // 获得用户信息
    wx.getSetting({
      success: (response) => {
        console.log("getSetting",response)
        // typeof cb == "function" && cb()
        // 没有授权需要弹框
        if (!response.authSetting['scope.userInfo']) {
          that.setData({
            showInfoModel: true,
            infoFun:cb,
            infoFailFun:failcb||null
          })
        }
        else{ 
          // 判断用户已经授权。不需要弹框
          that.setData({
            showInfoModel: false
          })
          typeof cb == "function" && cb()
        }
      },
      fail: function () {
        wx.showToast({
          title: '系统提示:网络错误',
          icon: 'warn',
          duration: 1500,
        })
      }
    })
  },
  authorizeIndexInfo(cb,failcb){
    var that = this;
    if(!wx.getStorageSync('ISauthorizeInfo')){
      app.globalData.userInfo = wx.getStorageSync('userInfo');
      // console.log("******",app.globalData.userInfo,wx.getStorageSync('userInfo'),typeof(app.globalData.userInfo))
      // 获得用户信息
      wx.getSetting({
        success: (response) => {
          console.log("getSetting",response)
          // typeof cb == "function" && cb()
          // 没有授权需要弹框
          if (!response.authSetting['scope.userInfo']) {
            that.setData({
              showInfoModel: true,
              infoFun:cb,
              infoFailFun:failcb||null
            })
          }
          else{ 
            // 判断用户已经授权。不需要弹框
            that.setData({
              showInfoModel: false
            })
            typeof cb == "function" && cb()
          }
        },
        fail: function () {
          // typeof cb == "function" && cb()
          wx.showToast({
            title: '系统提示:网络错误',
            icon: 'warn',
            duration: 1500,
          })
        }
      })
    }
    else{
      typeof cb == "function" && cb()
    }
  },
  userPhone:function(e){
    console.log(e,'寂静欢喜')
    this.setData({
      tel: e.detail.value
    })
  },
  verifyCode:function(e){
        console.log(e,'yuan')
        this.setData({
            verifyCode: e.detail.value
        })
  },
    getVerifyCode:function(){//验证码
        var that = this;
        if(that.data.isSend){
            return
        }
        if (!/^1\d{10}$/.test(that.data.tel)) {
            wx.showToast({
                title: '输入的手机号不合法',
                icon:"none",
                duration: 2000
            })
            return;
        }
        wx.request({
            url: util.url(),
            method:'POST',
            data: util.reformParam(util.verifyCode,{sms_mobile: that.data.tel, sms_template:'verification.code',sms_code:'SMS_004',sms_type: '1',sms_params: '{"":""}'}),
            success:function(){
                that.setData({
                    isSend:true
                })
                let time = 60;
                let time1 = setInterval(function(){
                    if(time>0){
                        time = time-1;
                        that.setData({
                            verifyText: time +'秒后获取'
                        })
                        //that.data.verifyText = time +'秒后获取'
                    }else{
                        that.setData({
                            verifyText:'获取验证码'
                        })
                        that.setData({
                            isSend:false
                        })
                        clearInterval(time1)
                    }
                },1000)
            },
            fail:function(){
                wx.showToast({
                    title: '网络连接出现问题，请稍后再试！',
                    icon:"none",
                    duration: 2000
                })
            }
        });
    },
    sendTel:function(){//点击打钩按钮
        var that = this;
        if(that.data.flag){
            return
        }
        that.setData({
            flag:true
        });
        if (!/^1\d{10}$/.test(that.data.tel)) {
            wx.showToast({
                title: '请输入正确的手机号',
                icon:"none",
                duration: 2000
            });
            that.setData({
                flag:false
            });
            return;
        }
        console.log(that.data.verifyCode.length)
        if(that.data.verifyCode.length<1){
            wx.showToast({
                title: '验证码不能为空',
                icon:"none",
                duration: 2000
            });
            that.setData({
                flag:false
            });
            return;
        }
        
        wx.request({
            url: util.url(),
            method:'POST',
            data: util.reformParam(util.checkVerifyCodeEffective,{mobile: that.data.tel,type: 'verification.code',verifycode: that.data.verifyCode}),
            success:function(res){
                console.log(res,'//////')
                if(res.data.success){
                    that.telData();
                    that.setData({
                        dialog:true
                    });
                    setTimeout(function(){
                        that.setData({
                            dialog:false
                        });
                        // wx.navigateTo({
                        //     url: '../index/index'
                        // });
                    },2000);
                }else{
                    wx.showToast({
                        title: res.data.message,
                        icon:"none",
                        duration: 2000
                    });
                    that.setData({
                        flag:false
                    });
                }
            },
            fail:function(re){
                wx.showToast({
                    title: res.data.message,
                    icon:"none",
                    duration: 2000
                });
                that.setData({
                    flag:false
                });
            }
        });		
    },
    telData:function(){//留电接口
        var that = this;
        var houseid = app.globalData.houseid;
        var pages = getCurrentPages();
        var currentPage = pages[pages.length-1]
        var urlhref = currentPage.route;
        console.log('当前页面链接',currentPage.route)
        wx.request({
            url: util.url(),
            method:'POST',
            data: util.reformParam(util.savephone,{houseid: houseid,name:app.globalData.loginid,channel:app.globalData.fromChannel,mobile: that.data.tel,platform:'3',refer:urlhref}),
            success:function(){
              wx.setStorageSync('indexLiudian',true)
                that.setData({
                    showPhoneAuth:true,
                    showAgree:true
                })
            },
            fail:function(re){

            }
        });
    },
})
